// sub_zhonghang/module2/page_yxtz/page1/page1.js
const dayjs = require("dayjs");
import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userId: "",
    pageNum: "1",
    pageSize: "10",
    serach_Val: "",
    startDate: dayjs(new Date(new Date().getTime())).format("YYYY-MM-DD"),
    endDate: dayjs(new Date(new Date().getTime())).format("YYYY-MM-DD"),
    matterType: "全部",
    matterTypeIndex: "0",
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      if (type === 'day') {
        return `${value}日`;
      }
      return value;
    },
    minDate: new Date(2022, 9, 1).getTime(),
    maxDate: new Date().getTime(),
    pf_date_in: new Date().getTime(),
    startDateIsshow: false,
    endDateIsshow: false,
    metterIsshow: false,
    matterArr: ["全部", "陌生拜访", "日常维护", "授信营销", "贷后维护", "其他事项"],
    proList: [],
    defaultTime: []
  },
  // methods
  addBtnClick() {
    wx.navigateTo({
      url: '/sub_zhonghang/module2/page_yxtz/page2/page2',
    })
  },
  toClockClick(e) {
    wx.navigateTo({
      url: `/sub_zhonghang/module2/page_yxtz/page3/page3?shortName=${e.currentTarget.dataset.shortname}&corpName=${e.currentTarget.dataset.corpname}&corpCredit=${e.currentTarget.dataset.corpcredit}&recordId=${e.currentTarget.dataset.recordid}`,
    })
  },
  startDateclick() {
    this.setData({
      startDateIsshow: true,
    })
  },
  endDateclick() {
    this.setData({
      endDateIsshow: true,
    })
  },
  startDateCancel() {
    this.setData({
      startDateIsshow: false,
      endDateIsshow: false,
    })
  },
  onSearch(e) {
    console.log(e);
    this.setData({
      serach_Val: e.detail,
      proList: [],
      pageNum: "1"
    })
    this.getList()
  },
  startDateConfirm(e) {
    console.log(dayjs(new Date(e.detail[0])).format("YYYY-MM-DD"));
    this.setData({
      startDate: dayjs(new Date(e.detail[0])).format("YYYY-MM-DD"),
      endDate: dayjs(new Date(e.detail[1])).format("YYYY-MM-DD"),
      proList: [],
      pageNum: "1",
      startDateIsshow: false
    })
    this.getList()
  },
  endDateConfirm(e) {
    this.setData({
      endDate: dayjs(new Date(e.detail)).format("YYYY-MM-DD"),
      proList: [],
      pageNum: "1",
      endDateIsshow: false
    })
  },
  matterTypeClick() {
    this.setData({
      metterIsshow: true,
    })
  },
  metterCancel() {
    this.setData({
      metterIsshow: false,
    })
  },
  metterConfirm(e) {
    console.log(e);
    this.setData({
      matterType: e.detail.value,
      matterTypeIndex: e.detail.index,
      proList: [],
      pageNum: "1",
      metterIsshow: false
    })
    this.getList()
  },
  itemClick(e) {
    console.log(e);
    wx.navigateTo({
      url: '/sub_zhonghang/module2/page_yxtz/page2/page2?recordId=' + e.currentTarget.dataset.recordid,
    })
  },
  // 滚动到底部
  scrollBottom() {
    this.data.pageNum ++
    this.setData({
      pageNum: this.data.pageNum
    })
    this.getList()
  },
  getList() {
    wx.showLoading()
    let prams = {
      corpName: this.data.serach_Val,
      startTime: this.data.startDate,
      endTime: this.data.endDate,
      meetItems: this.data.matterTypeIndex == 0 ? '' : this.data.matterTypeIndex * 1,
      pageBO: {
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize
      },
      userId: this.data.userId
    }
    console.log(prams);
    getApp().globalData.request('/boc/bocSales/getSaleLedgerList', prams, "POST", ).then(res => {
      console.log(res);
      if (res.code == 200) {
        wx.hideLoading()
      }
      this.setData({
        proList: this.data.proList.concat(res.data.list)
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log(options);
    if (options.userId) {
      this.setData({
        userId: options.userId,
        proList: [],
        pageNum: 1,
        startDate: options.beginDate,
        endDate: options.endDate,
        defaultTime: [options.beginDate, options.endDate],
      })
    }
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (this.data.refresh) {
      this.setData({
        proList: [],
        pageNum: 1
      })
      this.getList()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})